﻿'
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2010
' by DotNetNuke Corporation
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
'

Imports DotNetNuke.Modules.Media.MediaController
Imports System.Text
Imports System.Text.RegularExpressions
Imports System.Web

Namespace DotNetNuke.Modules.Media.Utilities

    Public NotInheritable Class MediaMarkUpUtility

#Region " Constants "

        Private Const OPEN_BRACKET As String = "<"
        Private Const CLOSE_BRACKET As String = ">"
        Private Const SELF_CLOSE_BRACKET As String = "/>"
        Private Const SPACE As String = " "
        Private Const OPEN_TAG_FORMAT As String = "<{0} "
        Private Const CLOSE_TAG_FORMAT As String = "</{0}>"
        Private Const PARAM_TAG_FORMAT As String = "<param name=""{0}"" value=""{1}"" />"

        Private Const DIV_TAG As String = "div"
        Private Const ANCHOR_TAG As String = "a"
        Private Const IMAGE_TAG As String = "img"
        Private Const PARAM_TAG As String = "param"
        Private Const OBJECT_TAG As String = "object"
        Private Const EMBED_TAG As String = "embed"

        Private Const ID_ATTRIBUTE As String = "id=""{0}"" "
        Private Const CLASS_ATTRIBUTE As String = "class=""{0}"" "
        Private Const DATA_ATTRIBUTE As String = "data=""{0}"" "
        Private Const SRC_ATTRIBUTE As String = "src=""{0}"" "
        Private Const ALT_ATTRIBUTE As String = "alt=""{0}"" "
        Private Const TITLE_ATTRIBUTE As String = "title=""{0}"" "
        Private Const NAME_ATTRIBUTE As String = "name=""{0}"" "
        Private Const VALUE_ATTRIBUTE As String = "value=""{0}"" "
        Private Const WIDTH_ATTRIBUTE As String = "width=""{0}"" "
        Private Const HEIGHT_ATTRIBUTE As String = "height=""{0}"" "
        Private Const LOOP_ATTRIBUTE As String = "loop=""{0}"" "
        Private Const HREF_ATTRIBUTE As String = "href=""{0}"" "
        Private Const TARGET_ATTRIBUTE As String = "target=""{0}"" "
        Private Const AUTOSTART_ATTRIBUTE As String = "autostart=""{0}"" "
        Private Const AUTOPLAY_ATTRIBUTE As String = "autoplay=""{0}"" "
        Private Const STYLE_ATTRIBUTE As String = "style=""width:{0}px;height:{1};"" "

        Private Const DIV_ID_PREFIX As String = "div_"
        Private Const IMAGE_ID_PREFIX As String = "image_"
        Private Const ANCHOR_ID_PREFIX As String = "a_"
        Private Const FLASH_ID_PREFIX As String = "flash_"
        Private Const WINDOWS_MEDIA_ID_PREFIX As String = "windowsmedia_"
        Private Const REAL_PLAYER_ID_PREFIX As String = "realplayer_"
        Private Const QUICKTIME_ID_PREFIX As String = "quicktime_"

        Private Const AUTOSTART As String = "autostart"
        Private Const SRC As String = "src"
        Private Const URL As String = "url"
        Private Const AUTOPLAY As String = "autoplay"
        Private Const MEDIA_LOOP As String = "loop"

        Private Const DIV_CLASS As String = "dnnmedia_wrapper"
        Private Const MEDIA_IMAGE_CLASS As String = "dnnmedia_image"
        Private Const ALIGN_LEFT_CLASS As String = "dnnmedia_left"
        Private Const ALIGN_RIGHT_CLASS As String = "dnnmedia_right"
        Private Const ALIGN_CENTER_CLASS As String = "dnnmedia_center"

#End Region

        Private p_CurrentDomain As String = Null.NullString
        Private ReadOnly Property CurrentDomain() As String
            Get
                If Not String.IsNullOrEmpty(p_CurrentDomain) Then
                    Return p_CurrentDomain
                End If

                Dim pSettings As Entities.Portals.PortalSettings
                pSettings = Entities.Portals.PortalController.GetCurrentPortalSettings

                If HttpContext.Current.Request.IsSecureConnection Then
                    p_CurrentDomain = String.Concat("https://", pSettings.PortalAlias.HTTPAlias)
                Else
                    p_CurrentDomain = String.Concat("http://", pSettings.PortalAlias.HTTPAlias)
                End If

                Return p_CurrentDomain
            End Get
        End Property

#Region " RegEx Patterns "

        Private Const IMAGE_PATTERN As String = "\.(jpg|jpeg?|gif|bmp|png)"
        Private Const FLASH_PATTERN As String = "\.swf"
        Private Const WINDOWS_MEDIA_PATTERN As String = "\.(avi|wmv|midi|wav|asx|mp3|mpeg|asf|wma)"
        Private Const REAL_PLAYER_PATTERN As String = "\.(ram|rpm|rm)"
        Private Const QUICKTIME_PATTERN As String = "\.(mov|qt)"

#End Region

#Region " Get Media Type "

        Public Overloads Function GetMediaType(ByVal Media As MediaInfo) As MediaType
            Return GetMediaType(Media.Src)
        End Function

        Public Overloads Function GetMediaType(ByVal MediaURL As String) As MediaType

            If Regex.IsMatch(MediaURL, IMAGE_PATTERN, RegexOptions.IgnoreCase) Then
                Return MediaType.Image
            ElseIf Regex.IsMatch(MediaURL, FLASH_PATTERN, RegexOptions.IgnoreCase) Then
                Return MediaType.Flash
            ElseIf Regex.IsMatch(MediaURL, WINDOWS_MEDIA_PATTERN, RegexOptions.IgnoreCase) Then
                Return MediaType.WindowsMedia
            ElseIf Regex.IsMatch(MediaURL, QUICKTIME_PATTERN, RegexOptions.IgnoreCase) Then
                Return MediaType.Quicktime
            ElseIf Regex.IsMatch(MediaURL, REAL_PLAYER_PATTERN, RegexOptions.IgnoreCase) Then
                Return MediaType.RealPlayer
            Else
                Return MediaType.Unknown
            End If

        End Function

#End Region

#Region " Get Media Mark-Up "

        Public Function GetImageMarkUp(ByVal Media As MediaInfo, ByVal ModuleConfig As Entities.Modules.ModuleInfo) As String

            Dim strTagId As String = String.Concat(IMAGE_ID_PREFIX, Media.ModuleID.ToString)
            Dim strAnchorId As String = String.Concat(ANCHOR_ID_PREFIX, strTagId)
            Dim strDivId As String = String.Concat(DIV_ID_PREFIX, strTagId)
            Dim strDivCssClass As String = String.Concat(DIV_CLASS, GetMediaAlignment(Media.MediaAlignment, ModuleConfig))

            '
            ' BUILD:
            ' <div id="" class="">
            ' <img id="" class="" src="" alt="" title="" />
            ' </div>
            '

            Dim sb As New StringBuilder(10)

            ' build open div
            sb.AppendFormat(OPEN_TAG_FORMAT, DIV_TAG)
            sb.AppendFormat(ID_ATTRIBUTE, strDivId)
            sb.AppendFormat(CLASS_ATTRIBUTE.Trim, strDivCssClass)
            sb.Append(CLOSE_BRACKET)
            '

            ' build open anchor tag
            If Not String.IsNullOrEmpty(Media.NavigateUrl) Then
                sb.AppendFormat(OPEN_TAG_FORMAT, ANCHOR_TAG)
                sb.AppendFormat(ID_ATTRIBUTE, strAnchorId)
                sb.AppendFormat(HREF_ATTRIBUTE, FormatURL(Media.NavigateUrl, Media.TrackClicks, ModuleConfig.TabID, ModuleConfig.ModuleID))
                If Media.NewWindow Then
                    sb.AppendFormat(TARGET_ATTRIBUTE, "_blank")
                End If
                sb.Append(CLOSE_BRACKET)
            End If
            '

            ' begin building the image tag
            sb.AppendFormat(OPEN_TAG_FORMAT, IMAGE_TAG)
            sb.AppendFormat(ID_ATTRIBUTE, strTagId)
            sb.AppendFormat(CLASS_ATTRIBUTE, MEDIA_IMAGE_CLASS)
            sb.AppendFormat(SRC_ATTRIBUTE, Media.Src)
            If Not String.IsNullOrEmpty(Media.Alt) Then
                sb.AppendFormat(ALT_ATTRIBUTE, Media.Alt)
                sb.AppendFormat(TITLE_ATTRIBUTE, Media.Alt)
            Else
                ' for XHTML compliance
                sb.AppendFormat(ALT_ATTRIBUTE, String.Empty)
            End If
            If Media.Width > Null.NullInteger And Media.Height > Null.NullInteger Then
                sb.AppendFormat(STYLE_ATTRIBUTE, Media.Width.ToString, Media.Height.ToString)
            End If
            sb.Append(SELF_CLOSE_BRACKET)
            '

            ' build close anchor
            If Not String.IsNullOrEmpty(Media.NavigateUrl) Then
                sb.AppendFormat(CLOSE_TAG_FORMAT, ANCHOR_TAG)
            End If
            '

            ' build close div
            sb.AppendFormat(CLOSE_TAG_FORMAT, DIV_TAG)
            '

            Return sb.ToString

        End Function

        Public Function GetFlashMarkUp(ByVal Media As MediaInfo, ByVal ModuleConfig As Entities.Modules.ModuleInfo) As String

            Dim strFlashId As String = String.Concat(FLASH_ID_PREFIX, Media.ModuleID.ToString)
            Dim strDivId As String = String.Concat(DIV_ID_PREFIX, strFlashId)
            Dim strDivCssClass As String = String.Concat(DIV_CLASS, GetMediaAlignment(Media.MediaAlignment, ModuleConfig))

            'Media.Src = String.Concat(CurrentDomain, Media.Src)

            '
            ' BUILD:
            ' <div id="" class="">
            ' <embed pluginspage="http://www.macromedia.com/go/getflashplayer" src="" width="" height="" type="application/x-shockwave-flash" bgcolor="" salign="LT" quality="high" menu="false" loop=""></embed>
            ' </div>
            '

            Dim sb As New StringBuilder(10)

            ' build open div
            sb.AppendFormat(OPEN_TAG_FORMAT, DIV_TAG)
            sb.AppendFormat(ID_ATTRIBUTE, strDivId)
            sb.AppendFormat(CLASS_ATTRIBUTE.Trim, strDivCssClass)
            sb.Append(CLOSE_BRACKET)
            '

            ' build flash object
            'sb.Append(OPEN_BRACKET)
            'sb.Append(EMBED_TAG)
            'sb.Append(" pluginspage=""http://www.macromedia.com/go/getflashplayer"" ")
            'If Media.Width > Null.NullInteger Then
            '    sb.AppendFormat(WIDTH_ATTRIBUTE, Media.Width)
            'End If
            'If Media.Height > Null.NullInteger Then
            '    sb.AppendFormat(HEIGHT_ATTRIBUTE, Media.Height)
            'End If
            'sb.AppendFormat(TITLE_ATTRIBUTE, Media.Alt)
            'sb.Append("type=""application/x-shockwave-flash"" bgcolor="""" salign=""LT"" quality=""high"" menu=""false"" wmode=""transparent"" ")
            'sb.AppendFormat(LOOP_ATTRIBUTE.Trim, Media.MediaLoop.ToString.ToLower)
            'sb.Append(CLOSE_BRACKET)
            'sb.AppendFormat(CLOSE_TAG_FORMAT, EMBED_TAG)
            sb.AppendFormat(OPEN_TAG_FORMAT, OBJECT_TAG)
            sb.AppendFormat(ID_ATTRIBUTE, strFlashId)
            If Media.Width > Null.NullInteger Then
                sb.AppendFormat(WIDTH_ATTRIBUTE, Media.Width)
            End If
            If Media.Height > Null.NullInteger Then
                sb.AppendFormat(HEIGHT_ATTRIBUTE, Media.Height)
            End If
            sb.Append("classid=""clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"" ")
            sb.AppendFormat("codebase=""http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0""")
            sb.Append(CLOSE_BRACKET)
            sb.AppendFormat(PARAM_TAG_FORMAT, "movie", Media.Src)
            sb.AppendFormat(PARAM_TAG_FORMAT, "quality", "high")
            sb.AppendFormat(PARAM_TAG_FORMAT, "bgcolor", "#ffffff")
            sb.AppendFormat(PARAM_TAG_FORMAT, "wmode", "transparent")
            sb.Append("<!--[if !IE]> <-->")
            sb.AppendFormat(OPEN_TAG_FORMAT, OBJECT_TAG)
            sb.AppendFormat(DATA_ATTRIBUTE, Media.Src)
            If Media.Width > Null.NullInteger Then
                sb.AppendFormat(WIDTH_ATTRIBUTE, Media.Width)
            End If
            If Media.Height > Null.NullInteger Then
                sb.AppendFormat(HEIGHT_ATTRIBUTE, Media.Height)
            End If
            sb.Append("type=""application/x-shockwave-flash""")
            sb.Append(CLOSE_BRACKET)
            sb.AppendFormat(PARAM_TAG_FORMAT, "quality", "high")
            sb.AppendFormat(PARAM_TAG_FORMAT, "bgcolor", "#ffffff")
            sb.AppendFormat(PARAM_TAG_FORMAT, "wmode", "transparent")
            sb.AppendFormat(PARAM_TAG_FORMAT, "pluginurl", "http://www.macromedia.com/go/getflashplayer")
            sb.AppendFormat(PARAM_TAG_FORMAT, "wmode", "transparent")
            sb.AppendFormat(CLOSE_TAG_FORMAT, OBJECT_TAG)
            sb.Append("<!--> <![endif]-->")
            sb.AppendFormat(CLOSE_TAG_FORMAT, OBJECT_TAG)
            '

            ' build close div
            sb.AppendFormat(CLOSE_TAG_FORMAT, DIV_TAG)
            '

            Return sb.ToString

        End Function

        Public Function GetWindowsMediaMarkUp(ByVal Media As MediaInfo, ByVal ModuleConfig As Entities.Modules.ModuleInfo) As String

            Dim strWMediaId As String = String.Concat(WINDOWS_MEDIA_ID_PREFIX, Media.ModuleID.ToString)
            Dim strDivId As String = String.Concat(DIV_ID_PREFIX, strWMediaId)
            Dim strDivCssClass As String = String.Concat(DIV_CLASS, GetMediaAlignment(Media.MediaAlignment, ModuleConfig), " dnnmedia_wmp")

            '
            ' BUILD:
            ' <div id="" class="">
            ' <embed src="" width="" height="" autostart="" loop="" pluginspage="http://download.microsoft.com/download/winmediaplayer/nsplugin/6.4/WIN98/EN-US/wmpplugin.exe" type="application/x-mplayer2"></embed>
            ' </div>
            '

            Dim sb As New StringBuilder(10)

            ' build open div
            sb.AppendFormat(OPEN_TAG_FORMAT, DIV_TAG)
            sb.AppendFormat(ID_ATTRIBUTE, strDivId)
            sb.AppendFormat(CLASS_ATTRIBUTE.Trim, strDivCssClass)
            sb.Append(CLOSE_BRACKET)
            '

            ' build windows media object
            'sb.AppendFormat(OPEN_TAG_FORMAT, EMBED_TAG)
            'sb.AppendFormat(ID_ATTRIBUTE, strWMediaId)
            'sb.AppendFormat(SRC_ATTRIBUTE, Media.Src)
            'If Media.Width > Null.NullInteger Then
            '    sb.AppendFormat(WIDTH_ATTRIBUTE, Media.Width)
            'End If
            'If Media.Height > Null.NullInteger Then
            '    sb.AppendFormat(HEIGHT_ATTRIBUTE, Media.Height)
            'End If
            'sb.AppendFormat(AUTOSTART_ATTRIBUTE, Media.AutoStart.ToString.ToLower)
            'sb.AppendFormat(LOOP_ATTRIBUTE, Media.MediaLoop.ToString.ToLower)
            'sb.AppendFormat("pluginspage=""http://download.microsoft.com/download/winmediaplayer/nsplugin/6.4/WIN98/EN-US/wmpplugin.exe"" type=""application/x-mplayer2"" wmode=""transparent""")
            'sb.Append(CLOSE_BRACKET)
            'sb.AppendFormat(CLOSE_TAG_FORMAT, EMBED_TAG)
            sb.AppendFormat(OPEN_TAG_FORMAT, OBJECT_TAG)
            sb.AppendFormat(ID_ATTRIBUTE, strWMediaId)
            If Media.Width > Null.NullInteger Then
                sb.AppendFormat(WIDTH_ATTRIBUTE, Media.Width)
            End If
            If Media.Height > Null.NullInteger Then
                sb.AppendFormat(HEIGHT_ATTRIBUTE, Media.Height)
            End If
            sb.Append("classid=""clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6""")
            sb.Append(CLOSE_BRACKET)
            sb.AppendFormat(PARAM_TAG_FORMAT, "url", Media.Src)
            sb.AppendFormat(PARAM_TAG_FORMAT, "src", Media.Src)
            sb.AppendFormat(PARAM_TAG_FORMAT, "showcontrols", "true")
            sb.AppendFormat(PARAM_TAG_FORMAT, AUTOSTART, Media.AutoStart.ToString.ToLower)
            sb.Append("<!--[if !IE]> <-->")
            sb.AppendFormat(OPEN_TAG_FORMAT, OBJECT_TAG)
            sb.AppendFormat(DATA_ATTRIBUTE, Media.Src)
            If Media.Width > Null.NullInteger Then
                sb.AppendFormat(WIDTH_ATTRIBUTE, Media.Width)
            End If
            If Media.Height > Null.NullInteger Then
                sb.AppendFormat(HEIGHT_ATTRIBUTE, Media.Height)
            End If
            sb.Append("type=""video/x-ms-wmv""")
            sb.Append(CLOSE_BRACKET)
            sb.AppendFormat(PARAM_TAG_FORMAT, "src", Media.Src)
            sb.AppendFormat(PARAM_TAG_FORMAT, "controller", "true")
            sb.AppendFormat(PARAM_TAG_FORMAT, AUTOSTART, Media.AutoStart.ToString.ToLower)
            sb.AppendFormat(CLOSE_TAG_FORMAT, OBJECT_TAG)
            sb.Append("<!--> <![endif]-->")
            sb.AppendFormat(CLOSE_TAG_FORMAT, OBJECT_TAG)
            '

            ' build close div
            sb.AppendFormat(CLOSE_TAG_FORMAT, DIV_TAG)
            '

            Return sb.ToString

        End Function

        Public Function GetRealPlayerMarkUp(ByVal Media As MediaInfo, ByVal ModuleConfig As Entities.Modules.ModuleInfo) As String

            Dim strRMediaId As String = String.Concat(REAL_PLAYER_ID_PREFIX, Media.ModuleID.ToString)
            Dim strDivId As String = String.Concat(DIV_ID_PREFIX, strRMediaId)
            Dim strDivCssClass As String = String.Concat(DIV_CLASS, GetMediaAlignment(Media.MediaAlignment, ModuleConfig), " dnnmedia_wmp")

            '
            ' BUILD:
            ' <div id="" class="">
            ' <object classid="clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA" width="" height="">
            ' <param name="src" value="" />
            ' <param name="controls" value="ImageWindow" />
            ' <param name="console" value="one" />
            ' <param name="autostart" value="true" />
            ' <param name="wmode" value="transparent" />
            ' <embed src="" width="" height="" nojava="true" controls="ImageWindow" console="one" autostart="" wmode="transparent"></embed>
            ' </object>
            ' </div>
            '

            Dim sb As New StringBuilder(10)

            ' build open div
            sb.AppendFormat(OPEN_TAG_FORMAT, DIV_TAG)
            sb.AppendFormat(ID_ATTRIBUTE, strDivId)
            sb.AppendFormat(CLASS_ATTRIBUTE.Trim, strDivCssClass)
            sb.Append(CLOSE_BRACKET)
            '

            ' build real media player object
            'sb.AppendFormat(OPEN_TAG_FORMAT, OBJECT_TAG)
            'sb.AppendFormat(ID_ATTRIBUTE, strRMediaId)
            'If Media.Width > Null.NullInteger Then
            '    sb.AppendFormat(WIDTH_ATTRIBUTE, Media.Width)
            'End If
            'If Media.Height > Null.NullInteger Then
            '    sb.AppendFormat(HEIGHT_ATTRIBUTE, Media.Height)
            'End If
            'sb.Append("classid=""clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA""")
            'sb.Append(CLOSE_BRACKET)
            'sb.AppendFormat(PARAM_TAG_FORMAT, SRC, Media.Src)
            'sb.AppendFormat(PARAM_TAG_FORMAT, "controls", "ImageWindow")
            'sb.AppendFormat(PARAM_TAG_FORMAT, "console", "one")
            'sb.AppendFormat(PARAM_TAG_FORMAT, AUTOSTART, Media.AutoStart)
            'sb.AppendFormat(OPEN_TAG_FORMAT, EMBED_TAG)
            'sb.AppendFormat(SRC_ATTRIBUTE, Media.Src)
            'If Media.Width > Null.NullInteger Then
            '    sb.AppendFormat(WIDTH_ATTRIBUTE, Media.Width)
            'End If
            'If Media.Height > Null.NullInteger Then
            '    sb.AppendFormat(HEIGHT_ATTRIBUTE, Media.Height)
            'End If
            'sb.AppendFormat(AUTOSTART_ATTRIBUTE, Media.AutoStart.ToString.ToLower)
            'sb.Append("nojava=""true"" controls=""ImageWindow"" console=""one""")
            'sb.Append(CLOSE_BRACKET)
            'sb.AppendFormat(CLOSE_TAG_FORMAT, EMBED_TAG)
            'sb.AppendFormat(CLOSE_TAG_FORMAT, OBJECT_TAG)
            '
            '
            '
            sb.AppendFormat(OPEN_TAG_FORMAT, OBJECT_TAG)
            sb.AppendFormat(ID_ATTRIBUTE, strRMediaId)
            If Media.Width > Null.NullInteger Then
                sb.AppendFormat(WIDTH_ATTRIBUTE, Media.Width)
            End If
            If Media.Height > Null.NullInteger Then
                sb.AppendFormat(HEIGHT_ATTRIBUTE, Media.Height)
            End If
            sb.Append("classid=""clsid:CFCDAA03-8BE4-11cf-B84B-0020AFBBCCFA""")
            sb.Append(CLOSE_BRACKET)
            sb.AppendFormat(PARAM_TAG_FORMAT, SRC, Media.Src)
            sb.AppendFormat(PARAM_TAG_FORMAT, MEDIA_LOOP, Media.MediaLoop)
            sb.AppendFormat(PARAM_TAG_FORMAT, "controls", "ImageWindow")
            sb.AppendFormat(PARAM_TAG_FORMAT, "maintainaspect", "true")
            'sb.AppendFormat(PARAM_TAG_FORMAT, "console", "_unique")
            sb.AppendFormat(PARAM_TAG_FORMAT, AUTOSTART, Media.AutoStart.ToString.ToLower)
            sb.Append("<!--[if !IE]> <-->")
            sb.AppendFormat(OPEN_TAG_FORMAT, OBJECT_TAG)
            sb.AppendFormat(DATA_ATTRIBUTE, Media.Src)
            If Media.Width > Null.NullInteger Then
                sb.AppendFormat(WIDTH_ATTRIBUTE, Media.Width)
            End If
            If Media.Height > Null.NullInteger Then
                sb.AppendFormat(HEIGHT_ATTRIBUTE, Media.Height)
            End If
            sb.Append("type=""audio/x-pn-realaudio-plugin""")
            sb.Append(CLOSE_BRACKET)
            sb.AppendFormat(PARAM_TAG_FORMAT, SRC, Media.Src)
            sb.AppendFormat(PARAM_TAG_FORMAT, MEDIA_LOOP, Media.MediaLoop)
            sb.AppendFormat(PARAM_TAG_FORMAT, AUTOSTART, Media.AutoStart.ToString.ToLower)
            sb.AppendFormat(PARAM_TAG_FORMAT, "nojava", "true")
            sb.AppendFormat(PARAM_TAG_FORMAT, "controls", "ImageWindow")
            sb.AppendFormat(PARAM_TAG_FORMAT, "maintainaspect", "true")
            'sb.AppendFormat(PARAM_TAG_FORMAT, "console", "_unique")
            sb.AppendFormat(CLOSE_TAG_FORMAT, OBJECT_TAG)
            sb.Append("<!--> <![endif]-->")
            sb.AppendFormat(CLOSE_TAG_FORMAT, OBJECT_TAG)
            '

            ' build close div
            sb.AppendFormat(CLOSE_TAG_FORMAT, DIV_TAG)
            '

            Return sb.ToString

        End Function

        Public Function GetQuicktimeMarkUp(ByVal Media As MediaInfo, ByVal ModuleConfig As Entities.Modules.ModuleInfo) As String

            Dim strQMediaId As String = String.Concat(QUICKTIME_ID_PREFIX, Media.ModuleID.ToString)
            Dim strDivId As String = String.Concat(DIV_ID_PREFIX, strQMediaId)
            Dim strDivCssClass As String = String.Concat(DIV_CLASS, GetMediaAlignment(Media.MediaAlignment, ModuleConfig), " dnnmedia_wmp")

            '
            ' BUILD:
            ' <div id="" class="">
            ' <object classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" codebase="http://www.apple.com/qtactivex/qtplugin.cab" width="" height="">
            ' <param name="src" value="" />
            ' <param name="autoplay" value="true" />
            ' <param name="controller" value="true" />
            ' <param name="loop" value="false" />
            ' <param name="type" value="video/quicktime" />
            ' <param name="target" value="myself" />
            ' <embed width="" height="" pluginspage="http://www.apple.com/quicktime/download/" src="" type="video/quicktime" autoplay="true" controller="true" loop="false" target="myself"></embed>
            ' </object>
            ' </div>
            '

            Dim sb As New StringBuilder(10)

            ' build open div
            sb.AppendFormat(OPEN_TAG_FORMAT, DIV_TAG)
            sb.AppendFormat(ID_ATTRIBUTE, strDivId)
            sb.AppendFormat(CLASS_ATTRIBUTE.Trim, strDivCssClass)
            sb.Append(CLOSE_BRACKET)
            '

            ' build quicktime object
            'sb.AppendFormat(OPEN_TAG_FORMAT, OBJECT_TAG)
            'sb.AppendFormat(ID_ATTRIBUTE, strQMediaId)
            'sb.Append("classid=""clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6"" codebase=""http://www.apple.com/qtactivex/qtplugin.cab"" ")
            'If Media.Width > Null.NullInteger Then
            '    sb.AppendFormat(WIDTH_ATTRIBUTE, Media.Width)
            'End If
            'If Media.Height > Null.NullInteger Then
            '    sb.AppendFormat(HEIGHT_ATTRIBUTE, Media.Height)
            'End If
            'sb.Append(CLOSE_BRACKET)
            'sb.AppendFormat(PARAM_TAG_FORMAT, SRC, Media.Src)
            'sb.AppendFormat(PARAM_TAG_FORMAT, AUTOPLAY, Media.AutoStart)
            'sb.AppendFormat(PARAM_TAG_FORMAT, MEDIA_LOOP, Media.MediaLoop)
            'sb.Append("<param name=""controller"" value=""true"" /><param name=""type"" value=""video/quicktime"" /><param name=""target"" value=""myself"" />")
            'sb.AppendFormat(OPEN_TAG_FORMAT, EMBED_TAG)
            'sb.AppendFormat(WIDTH_ATTRIBUTE, Media.Width)
            'sb.AppendFormat(HEIGHT_ATTRIBUTE, Media.Height)
            'sb.AppendFormat(SRC_ATTRIBUTE, Media.Src)
            'sb.AppendFormat(AUTOPLAY_ATTRIBUTE, Media.AutoStart)
            'sb.AppendFormat(LOOP_ATTRIBUTE, Media.MediaLoop)
            'sb.Append("pluginspage=""http://www.apple.com/quicktime/download/"" type=""video/quicktime"" controller=""true"" target=""myself""")
            'sb.Append(CLOSE_BRACKET)
            'sb.AppendFormat(CLOSE_TAG_FORMAT, EMBED_TAG)
            'sb.AppendFormat(CLOSE_TAG_FORMAT, OBJECT_TAG)
            sb.AppendFormat(OPEN_TAG_FORMAT, OBJECT_TAG)
            sb.AppendFormat(ID_ATTRIBUTE, strQMediaId)
            If Media.Width > Null.NullInteger Then
                sb.AppendFormat(WIDTH_ATTRIBUTE, Media.Width)
            End If
            If Media.Height > Null.NullInteger Then
                sb.AppendFormat(HEIGHT_ATTRIBUTE, Media.Height)
            End If
            sb.Append("classid=""clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6"" ")
            sb.Append("codebase=""http://www.apple.com/qtactivex/qtplugin.cab""")
            sb.Append(CLOSE_BRACKET)
            sb.AppendFormat(PARAM_TAG_FORMAT, "src", Media.Src)
            sb.AppendFormat(PARAM_TAG_FORMAT, "controller", "true")
            sb.AppendFormat(PARAM_TAG_FORMAT, AUTOPLAY, Media.AutoStart)
            sb.AppendFormat(PARAM_TAG_FORMAT, MEDIA_LOOP, Media.MediaLoop)
            sb.Append("<!--[if !IE]> <-->")
            sb.AppendFormat(OPEN_TAG_FORMAT, OBJECT_TAG)
            sb.AppendFormat(DATA_ATTRIBUTE, Media.Src)
            If Media.Width > Null.NullInteger Then
                sb.AppendFormat(WIDTH_ATTRIBUTE, Media.Width)
            End If
            If Media.Height > Null.NullInteger Then
                sb.AppendFormat(HEIGHT_ATTRIBUTE, Media.Height)
            End If
            sb.Append("type=""video/quicktime""")
            sb.Append(CLOSE_BRACKET)
            sb.AppendFormat(PARAM_TAG_FORMAT, "controller", "true")
            sb.AppendFormat(PARAM_TAG_FORMAT, AUTOPLAY, Media.AutoStart)
            sb.AppendFormat(PARAM_TAG_FORMAT, MEDIA_LOOP, Media.MediaLoop)
            sb.AppendFormat(CLOSE_TAG_FORMAT, OBJECT_TAG)
            sb.Append("<!--> <![endif]-->")
            sb.AppendFormat(CLOSE_TAG_FORMAT, OBJECT_TAG)
            '

            ' build close div
            sb.AppendFormat(CLOSE_TAG_FORMAT, DIV_TAG)
            '

            Return sb.ToString

        End Function

#End Region

#Region " Private Methods "

        Private Function GetMediaAlignment(ByVal Alignment As Integer, ByVal ModuleConfig As Entities.Modules.ModuleInfo) As String
            Select Case Alignment
                Case 0 ' Use ModuleSettings values
                    If ModuleConfig.Alignment.Trim.Length > 0 Then
                        Select Case ModuleConfig.Alignment.ToLower
                            Case "left"
                                Return String.Concat(SPACE, ALIGN_LEFT_CLASS)
                            Case "center"
                                Return String.Concat(SPACE, ALIGN_CENTER_CLASS)
                            Case "right"
                                Return String.Concat(SPACE, ALIGN_RIGHT_CLASS)
                        End Select
                    End If

                    Return String.Empty
                Case 1 ' None 
                    Return String.Empty
                Case 2 ' Left
                    Return String.Concat(SPACE, ALIGN_LEFT_CLASS)
                Case 3 ' Center
                    Return String.Concat(SPACE, ALIGN_CENTER_CLASS)
                Case 4 ' Right
                    Return String.Concat(SPACE, ALIGN_RIGHT_CLASS)
                Case Else
                    Return String.Empty
            End Select
        End Function

        Private Function FormatURL(ByVal Link As String, ByVal TrackClicks As Boolean, ByVal TabId As Integer, ByVal ModuleId As Integer) As String
            Return EncodeUrl(Common.Globals.LinkClick(Link, TabId, ModuleId, TrackClicks))
        End Function

#End Region

    End Class

End Namespace